package hikari.persistence.handlersimpl;

import com.gooddies.wiring.annotations.WiringComponent;
import hikari.objects3d.Basic3dObject;
import hikari.objects3d.Custom3DObject;
import hikari.persistence.file.FileSection;
import hikari.persistence.persisthandlers.IPersistantObject3dReadHandler;
import hikari.persistence.persisthandlers.PersistantHandler;
import java.io.IOException;
import org.swig.jirr.IAnimatedMeshSceneNode;
import org.swig.jirr.ISceneManager;

/**
 * @author Dmitry
 */
@WiringComponent(singleton = true, lazy = true)
@PersistantHandler(sectionName = "anim")
public class AnimationLoadHandler implements IPersistantObject3dReadHandler {

    private AnimationLoadHandler() {
    }

    @Override
    public Basic3dObject read(ISceneManager sceneManager, Basic3dObject object, FileSection section) throws IOException {
        boolean tImmidiatelyAnimated = section.readBoolean(section.getChunk("immAnim"));
        boolean loop = section.readBoolean(section.getChunk("lp"));
        String selectedTrak = section.readString(section.getChunk("selTrk"));
        Custom3DObject object3d = (Custom3DObject) object;
        object3d.setImmidiatelyAnimated(tImmidiatelyAnimated);
        object3d.setSelectedAnimationTrac(selectedTrak);
        ((IAnimatedMeshSceneNode) object3d.getMeshSceneNode()).setLoopMode(loop);
        return object;
    }
}
